import request from '@/utils/request.js'
import store from '@/store'

export const loginAPI = ({ username, password }) => {
  return request({
    url: '/user/login',
    method: 'POST',
    data: {
      username,
      password
    }
  })
}

// 首页轮播图
export const swiperAPI = () => {
  return request({
    url: '/home/swiper'
  })
}
// 租房小组
export const groupsAPI = () => {
  return request({
    url: '/home/groups',
    params: {
      id: 'AREA|88cff55c-aaa4-e2e0'
    }
  })
}

// 获取城市列表
export const areaListAPI = () => {
  return request({
    url: '/area/city',
    params: {
      level: 1
    }
  })
}

// 获取热门城市
export const hotCityAPI = () => {
  return request({
    url: '/area/hot'
  })
}

// 根据城市名称查询该城市信息
export const cityInfoAPI = ({ name }) => {
  return request({
    url: '/area/info',
    params: {
      name
    }
  })
}

// 获取子级城市列表
export const cityListAPI = ({ id }) => {
  return request({
    url: '/area',
    params: {
      id
    }
  })
}

// 根据条件查询房屋
export const houseListAPI = ({ cityId, area, rentType, price, more }) => {
  return request({
    url: '/houses',
    params: {
      cityId,
      area,
      rentType,
      price,
      more
    }
  })
}

// 查询房源数据
export const areaHouseListAPI = ({ id }) => {
  return request({
    url: '/area/map',
    params: {
      id
    }
  })
}

// 获取房屋查询条件
export const housesSearchAPI = ({ id }) => {
  return request({
    url: '/houses/condition',
    params: {
      id
    }
  })
}

// 查询房屋具体信息
export const houseInfoAPI = (id) => {
  return request({
    url: `/houses/${id}`
  })
}

// 查看收藏列表
export const favoritesListAPI = () => {
  return request({
    url: '/user/favorites',
    headers: {
      authorization: store.state.Usertoken
    }
  })
}

// 查看已发布房源
export const userHouseListAPI = () => {
  return request({
    url: '/user/houses',
    headers: {
      authorization: store.state.Usertoken
    }
  })
}

// 发布房源
export const publishHouseAPI = obj => {
  return request({
    url: '/user/houses',
    method: 'POST',
    data: obj
  })
}

// 小区关键词
export const xiaoquAPI = ({ name, id }) => {
  return request({
    url: '/area/community',
    params: {
      name,
      id
    }
  })
}

// 添加收藏
export const favoritesHouse = (id) => {
  return request({
    url: `/user/favorites/${id}`,
    method: 'POST',
    headers: {
      authorization: store.state.Usertoken
    }
  })
}

// 删除收藏
export const unfavoritesHouse = (id) => {
  return request({
    url: `/user/favorites/${id}`,
    method: 'DELETE',
    headers: {
      authorization: store.state.Usertoken
    }
  })
}
